/**
 * Created by yangxianming on 2019/2/1.
 * 测试结果页面js
 */
function initData(){
    getDateList();
    //getReport(today, 1);


}

function queryReport(){
    var date = document.getElementById("date").value;
    getReport(date, 1);
}

function queryReportKeyboard(event){
    var e = event || window.event;
    if (e && e.keyCode ==13){
        var date = document.getElementById("date").value;
        getReport(date, 1);
    }
}



function getDateList(){
    var dateList = document.getElementById("date");
    dateList.innerText = "";

    var nodeAdd = selectedText(document.getElementById("node"));
    var par = "action=getLogDateList";
    par = par + "&node="+nodeAdd;

    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("get", "/mobNodes/mobNodesLogManger?" + par, true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    loadSelectList(document.getElementById("date"), r["result"]);
                }else{
                    alert(r["errorMsg"]);
                }
            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send();
}

function getReport(){
    //数据
    var date = selectedText(document.getElementById("date"));
    var nodeAdd = selectedText(document.getElementById("node"));
    var par = "action=getDateLog";
    par = par + "&node="+nodeAdd;
    par = par + "&date=" + date;

    var results = document.getElementsByClassName("content")[0];
    results.innerText = "";
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("get", "/mobNodes/mobNodesLogManger?" + par, true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    //加载列表
                    var listShell = document.createElement("div");
                    listShell.style.width = "80%";
                    listShell.style.marginLeft = "20px";
                    results.appendChild(listShell);
                    var resultArr = r["result"];
                    for(var index in resultArr){
                        var oneP = document.createElement("p");
                        oneP.innerText = resultArr[index];
                        oneP.style.cursor = "pointer";
                        oneP.onclick = function(){
                            var date1 = selectedText(document.getElementById("date"));
                            var nodeAdd1 = selectedText(document.getElementById("node"));
                            var logName = this.innerText;
                            var jumpUrl = "http://" + nodeAdd1 + "/airTestLog/" + date1 + "/" + logName + "/log.html";
                            //window.open(jumpUrl);
                            window.location.href = jumpUrl;
                        };
                        listShell.appendChild(oneP);
                    }
                }else{
                    alert(r["errorMsg"]);
                }
            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send();
}